package com.supor.aiot.common.ui.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;

import com.supor.aiot.common.R;

@SuppressLint("AppCompatCustomView")
public class DotTextView extends TextView {
    private int tipVisibility = 0;

    public DotTextView(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
        init(null);
    }

    public DotTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
        init(attrs);
    }

    public DotTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        // TODO Auto-generated constructor stub
        init(attrs);
    }

    public void init(AttributeSet attrs) {
        if(attrs != null) {
            TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.DotTextView);
            tipVisibility = array.getBoolean(R.styleable.DotTextView_DotVisible, false)?1:0;
            array.recycle();
        }
    }

    public void setDotVisible(boolean visible){
        if (visible){
            tipVisibility=1;
        }else {
            tipVisibility=0;
        }
        invalidate();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);
        if(tipVisibility == 1) {
            int width = getWidth();
            int paddingRight = getPaddingRight();
            Paint paint = new Paint();
            paint.setColor(getResources().getColor(R.color.primary_btn_bg));
            paint.setAntiAlias(true);
            paint.setDither(true);
            paint.setStyle(Paint.Style.FILL_AND_STROKE);
            float radius = getResources().getDimensionPixelSize(R.dimen.dp_15);
            canvas.drawCircle(width -radius/2, radius/2, radius/2, paint);
        }
    }

}
